const sql = require("mssql");
const config = require("../config")
function execFun(res,name,...vals){
    sql.connect(config, function (err) {
      if (err) console.log(err);
      var request = new sql.Request();
      let len = vals.length
      let vals1 = vals.slice(0,len/2)
      let vals2 = vals.slice(len/2,len)
      for(let i=0;i<vals1.length;i++){
        request.input(vals1[i], sql.VarChar,vals2[i]);
      }				  		  
      request.execute(name, function (err, data) {
        if (err) {
          console.log(err);
          res.end('error')
        }
        else {
          res.end(JSON.stringify(data.recordset))
        }
      })
    });
  }

  module.exports = execFun